<template>
  <section class="news-section">
    <div class="section-container">
      <h2 class="section-title">资讯动态</h2>
      <p class="section-subtitle">了解斑马中国最新动态，关注版权行业发展</p>

      <div class="news-content">
        <!-- 政策解读 -->
        <div class="news-card policy-news">
          <div class="news-header">
            <h3>政策解读</h3>
            <span class="view-more" @click="$emit('view-more')">
              <span>更多</span>
              <i class="el-icon-arrow-right"></i>
            </span>
          </div>
          
          <div 
            v-for="item in policyNews" 
            :key="item.id" 
            class="news-item"
            @click="$emit('view-detail', item.id)"
          >
            <h4 class="news-title" v-html="item.title.rendered"></h4>
            <div class="news-description" v-html="item.excerpt.rendered"></div>
            <p class="news-time">
              <i class="el-icon-time"></i>
              {{ formatTime(item.date_gmt) }}
            </p>
          </div>
        </div>

        <!-- 平台动态 -->
        <div class="news-card platform-news">
          <div class="news-header">
            <h3>平台动态</h3>
            <span class="view-more" @click="$emit('view-more')">
              <span>更多</span>
              <i class="el-icon-arrow-right"></i>
            </span>
          </div>

          <div 
            v-for="item in platformNews" 
            :key="item.id" 
            class="news-item"
            @click="$emit('view-detail', item.id)"
          >
            <h4 class="news-title" v-html="item.title.rendered"></h4>
            <div class="news-description" v-html="item.excerpt.rendered"></div>
            <p class="news-time">
              <i class="el-icon-time"></i>
              {{ formatTime(item.date_gmt) }}
            </p>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'NewsSection',

  props: {
    policyNews: {
      type: Array,
      required: true
    },
    platformNews: {
      type: Array, 
      required: true
    }
  },

  emits: ['view-detail', 'view-more'],

  setup() {
    const formatTime = (time) => {
      return moment(time).format('YYYY-MM-DD HH:mm:ss')
    }

    return {
      formatTime
    }
  }
})
</script>

<style lang="scss" scoped>
.news-section {
  padding: 80px 0;
  background: linear-gradient(to bottom, #f8f9fc, #f0f5fa);
  position: relative;
  
  &::before {
    content: '';
    position: absolute;
    top: -100px;
    left: -100px;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(83, 183, 215, 0.1) 0%, rgba(83, 183, 215, 0) 70%);
    z-index: 0;
  }
}

.section-container {
  width: $container-width;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  
  @media screen and (max-width: 1200px) {
    width: 90%;
  }
}

.section-title {
  font-size: 36px;
  color: #333;
  font-weight: 600;
  text-align: center;
  margin-bottom: 15px;
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(to right, $primary-color, lighten($primary-color, 15%));
  }
}

.section-subtitle {
  text-align: center;
  font-size: 18px;
  color: #666;
  margin: 30px auto;
  max-width: 600px;
}

.news-content {
  display: flex;
  gap: 30px;
  margin-top: 40px;
  
  @media screen and (max-width: 992px) {
    flex-direction: column;
  }
}

.news-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  padding: 30px;
  transition: all 0.3s ease;
  
  &:hover {
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.1);
    transform: translateY(-5px);
  }
}

.policy-news {
  width: 35%;
  
  @media screen and (max-width: 992px) {
    width: 100%;
  }
}

.platform-news {
  flex: 1;
}

.news-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eaeaea;

  h3 {
    font-size: 22px;
    color: #333;
    font-weight: 600;
    position: relative;
    padding-left: 15px;
    
    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 8px;
      height: 18px;
      width: 5px;
      background: $primary-color;
      border-radius: 3px;
    }
  }

  .view-more {
    font-size: 14px;
    color: #999;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;

    i {
      margin-left: 5px;
      transition: transform 0.3s ease;
    }

    &:hover {
      color: $primary-color;
      
      i {
        transform: translateX(3px);
      }
    }
  }
}

.news-item {
  padding: 20px 0;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: all 0.3s ease;
  
  &:last-child {
    border-bottom: none;
  }

  &:hover {
    .news-title {
      color: $primary-color;
    }
    
    transform: translateX(5px);
  }

  .news-title {
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
    transition: color 0.3s;
    font-weight: 600;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
  }

  .news-description {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    
    ::v-deep(p) {
      margin: 0;
    }
  }

  .news-time {
    font-size: 12px;
    color: #999;
    display: flex;
    align-items: center;
    
    i {
      margin-right: 5px;
      font-size: 14px;
    }
  }
}

@media screen and (max-width: 768px) {
  .news-section {
    padding: 60px 0;
  }
  
  .section-title {
    font-size: 28px;
  }
  
  .section-subtitle {
    font-size: 16px;
    margin: 25px auto;
  }
  
  .news-header {
    h3 {
      font-size: 20px;
    }
  }
  
  .news-item {
    padding: 15px 0;
    
    .news-title {
      font-size: 15px;
    }
    
    .news-description {
      font-size: 13px;
    }
  }
}
</style> 